package demo5;

/**
 * 子序列问题
 *      最长递增子序列的个数
 */
public class test3 {
    public int findNumberOfLIS(int[] nums) {
        // 创建dp表
        int n = nums.length;
        int[] len = new int[n];
        int[] count = new int[n];
        // 初始化
        for (int i = 0; i < n; i++) {
            len[i] = count[i] = 1;
        }
        int retLen = 1;
        int retCount = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    if (len[i] == len[j] + 1) {
                        count[i] += count[j];
                    } else if (len[i] < len[j]+1) {
                        len[i] = len[j]+1;
                        count[i] = count[j];
                    }
                }
            }
            if (retLen == len[i]){
                retCount += count[i];
            } else if(retLen < len[i]){
                retLen = len[i];
                retCount = count[i];
            }
        }
        return retCount;
    }
}
